import request from '@/services/http'
import type { ChatMessage } from '@/types/chat'

// 获取全部历史记录
export const getAllHistory = () => {
  return request({
    url: '/euc/api/chatHistory/list',
    method: 'get',
  })
}

interface HistoryParams {
  current?: number
  size?: number
  keyword?: string
}
// 分页获取聊天历史
export const getHistoryList = (params: HistoryParams) => {
  return request({
    url: '/euc/api/chatHistory/page',
    method: 'get',
    params,
  })
}

// 保存历史
export const saveHistory = (data: ChatMessage) => {
  return request({
    url: '/euc/api/chatHistory/save',
    method: 'post',
    data,
  })
}

// 删除历史
export const deleteHistory = (ids: string) => {
  return request({
    url: '/euc/api/chatHistory/delete',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data: { ids },
  })
}

// 通过历史记录进入会话
export const useHistoryInitChat = (sessionId: string) => {
  return request({
    url: `/euc/api/chatHistory/initChat?sessionId=${sessionId}`,
    method: 'get',
  })
}
